<template>
  <div>
    <dami-dialog @confirm="confirm" @cancel="cancel">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="标题">
          <el-input v-model="options.Title" placeholder="标题"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="内容">
          <el-input v-model="options.SubStance" placeholder="内容"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="Url">
          <el-input v-model="options.Url" placeholder="Url"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="图标">
          <upload ref='upload' :action-url='imgUploadPath' :multiple='false'></upload>
        </el-form-item>
      </el-form>

    </dami-dialog>
  </div>
</template>

<script type="text/javascript">
import upload from  '../../../component/upload';
import SYS_Message_add from  '../../../API/SYS_Message_add.js';
const config = require('../../../../config');
const imgUploadPath = !!process.env  ? config.dev.imgUploadPath : config.build.imgUploadPath;

  export default {
    data() {
       return {
           imgUploadPath:imgUploadPath,
           options:{
             Title:'',
             SubStance:'',
             Url:'',
             ImageUrl:''
           }
       }
    },
    components:{
      'upload':upload
    },
    methods:{
      cancel(){
        this.$emit("cancel");
        this.$refs.upload.reset();
      },
      confirm(){
        this.$refs.upload.upload(data => {
          if(data.res != "1"){
            this.$Message({
                message:data.mes
            });
            return;
          }
          let imgList = data.imgList[0];
          let imgPath = imgList.value;
          this.options.ImageUrl = imgPath;

          SYS_Message_add(this.options).then(data => {
            this.$Message({
                message:"操作成功"
            });
            this.$emit("confirm");
            this.$refs.upload.reset();
          }).catch(message => {
            this.$Message({
                message
            });
          });

        });



      }
    }
  }
</script>
